const loadLocaleMessages = async (): Promise<Record<string, any>> => {
  const locales = import.meta.glob("@/locales/*.json");
  const messages: Record<string, any> = {}; // 外部 messages 类型定义

  for (const path in locales) {
    const matchResult = path.match(/([a-z]{4})\.json$/i);
    const locale = matchResult ? matchResult[1] : null;
    if (!locale) {
      console.error(`无法从路径 ${path} 中提取语言代码`);
      continue;
    }
    const module = (await locales[path]()) as { default: any };
    messages[locale] = module.default;
  }
  return messages;
};

export default loadLocaleMessages;
